const request = require("./http.js");
//添加评论
var addEvaluate = function (data, callback) {
  request({
    url: "/mall/comment/insertCommentAndPic",
    method: "post",
    data: data,
    success: function (res) {
      callback(res);
    },
    fail: function (err) {
      console.log(err);
      wx.showToast({
        title: err.errMsg,
        icon: "none",
        duration: 2000,
      });
    },
  });
};
//查询评论
var searchComment= function(id,callback){
  request({
    url: "/mall/comment/queryById?id="+id,
    method: "get",
    success: function (res) {
      callback(res);
    },
    fail: function (err) {
      wx.showToast({
        title: err.errMsg,
        icon: "none",
        duration: 2000,
      });
    },
  });
}
//此用户过往的评价商品
var evaluateGoods = function (data, callback) {
  request({
    url: "/mall/comment/selectCustomerCommentAll",
    method: "post",
    data: data,
    success: function (res) {
      callback(res);
    },
    fail: function (err) {
      //console.log(err);
      wx.showToast({
        title: err.errMsg,
        icon: "none",
        duration: 2000,
      });
    },
  });
};
//此商品的所有评论
var getAllevaluate = function (data, callback) {
  request({
    url: "/mall/comment/selectSpuCommentAll",
    method: "post",
    data: data,
    success: function (res) {
      callback(res);
    },
    fail: function (err) {
      //console.log(err);
      wx.showToast({
        title: err.errMsg,
        icon: "none",
        duration: 2000,
      });
    },
  });
};
//此用户未评价商品
var getunComment = function (data, callback) {
  request({
    url: "/mall/comment/selectNotCommentAll",
    method: "post",
    data: data,
    success: function (res) {
      callback(res);
    },
    fail: function (err) {
      //console.log(err);
      wx.showToast({
        title: err.errMsg,
        icon: "none",
        duration: 2000,
      });
    },
  });
};


module.exports = {
  addEvaluate:addEvaluate,//添加评论
  searchComment:searchComment,//查询评论
  evaluateGoods:evaluateGoods,//此用户过往的评价商品
  getAllevaluate:getAllevaluate,//此商品的所有评论
  getunComment:getunComment,//此用户未评价商品
}